﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 策略模式
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cbxType.Items.AddRange(new object[] { "正常收费", "打八折", "满300减100" });
            cbxType.SelectedIndex = 0;
        }

        private double total = 0d;

        private void btnOK_Click(object sender, EventArgs e)
        {
            CashContext cashContext = new CashContext(this.cbxType.SelectedItem.ToString());
            double totalPrice = cashContext.GetResult(double.Parse(this.txtPrice.Text) * double.Parse(this.txtNum.Text));
            total += totalPrice;
            this.lbxList.Items.Add(string.Format("单价：{0} 数量：{1} {2} 合计：{3}", this.txtPrice.Text, this.txtNum.Text, this.cbxType.SelectedItem.ToString(), totalPrice));
            this.lblResult.Text = total.ToString();
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            this.txtNum.Text = string.Empty;
            this.txtPrice.Text = string.Empty;
        }
    }
}
